/**
 * @Author:卿雨欣
 * @Date:2020/6/23
 * @Description:这是管理cookie的组件
 */
export const  setCookie=(name,id)=>{
    document.cookie="name="+name;
    document.cookie="id="+id+";";
}

export const isCookie=()=>{
    if(document.cookie.split(';').length <= 0){
        return false;
    }else{
        let cs = document.cookie.split(";");
        for(let i = 0;i<cs.length;i++){
            let na=cs[i].split("=")[0];
            let c=cs[i].split("=")[1];
            if( (na === 'name' || na === ' name') && c.length !== 0){
                return true;
            }
        }
        return false;
    }
}

export const getCookiename=()=>{
    let con=document.cookie;
    if(con.length===0){
        return "";
    }else{
        let nas = document.cookie.split(";");
        for(let i = 0;i<nas.length;i++){
            let na=nas[i].split("=")[0];
            let c=nas[i].split("=")[1];
            if((na === 'name' || na === ' name')  && c.length !== 0){
                return c;
            }
        }
        return "";
    }
}

export const getCookieId=()=>{
    let con=document.cookie;
    if(con.length===0){
        return "";
    }else{
        let nas = document.cookie.split(";");
        for(let i = 0;i<nas.length;i++){
            let na=nas[i].split("=")[0];
            let c=nas[i].split("=")[1];
            if((na === 'id' || na ===' id')  && c.length !== 0){
                return c;
            }
        }
        return "";
    }
}

export const removeCookie=()=>{
    //清除cookie 将expires设置为当前时间
    var d = new Date();
    var data = d.getDate()-1;
    document.cookie = "name=;expires="+data
    document.cookie = "id=;expires="+data
    console.log("退出:"+document.cookie);
}
